#include "recognizer.h"

Recognizer::Recognizer()
{
    rs = new NothingRecognizerStrategy();
}

Recognizer::~Recognizer()
{
    delete rs;
}

bool Recognizer::openCamera()
{
    if (m_cap.isOpened())
        return true;
    m_cap.open(CV_CAP_ANY);
    return m_cap.isOpened();
}

Mat Recognizer::getFrame(double scale)
{
    m_cap >> m_frame;
    Size dsize = Size(m_frame.cols*scale,m_frame.rows*scale);
    resize(m_frame, m_frame, dsize);
    flip(m_frame, m_frame, 1);
    m_frame = rs->detect(m_frame);
    return m_frame;
}

void Recognizer::closeCamera()
{
    if (m_cap.isOpened())
        m_cap.release();
}

void Recognizer::setRecognizerStrategy(RecognizerStrategy *rs)
{
    delete this->rs;
    this->rs = rs;
}
